/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Utility;

/**
 *
 * @author labib
 */
import xmlMapping.*;
import CRUD.*;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;


public class MessageUtility {

    public static final String POLL_ADDED  = "Poll Added to thread ";   //FOR MSG TITLE
    public static final String POLL_ADDED_TO_THREAD_MARKER  = "Polls Added to thread you marked ";   //FOR MSG BODY
    //public static final String POLL_ADDED_TO_THREAD_CREATOR  = "Polls Added to thread you Ccreated ";   //FOR MSG BODY
    public static final String THREAD_ADDED = "Thread Added to forum ";
    //public static final String THREAD_ADDED_TO_THREAD_MARKER  = "Thread Added to forum you marked ";   //FOR MSG BODY
    public static final String POST_ADDED = "Post Added to thread ";
    public static final String POST_EDITED = "Post has been edited ";
    public static final String THREAD_EDITED = "Thread has been edited ";
    public static final String THREAD_REMOVED = "Thread has  been removed from forum ";
    public static final String FORUM_REMOVED = "Forum has removed from category ";
    public static final String MEMBER_SUSPEND = "You are suspended for a specific period , You can contact the moderator to solve the problem";
    public static final String MEMBER_BANNED = "You Are Banned , you won't be able to sign in again to our forum .. you can contact the moderator to solve the problem ";
    public static final String MEMBER_WARNING = "Warning !! ";
    public static final String REGISTERATION_LOCK = " You cannot register for a short period for maintenance , please try again after a while .";
    public static final String THREAD_LOCKED = "Sorry you cannot view this thread before you signed in .";
     public static final String BLOCKED_THREAD="ay haga";
             
             
    public static void sendMessage(Message msg) {

        MessageHome m = new MessageHome();
        m.persist(msg);

    }

    public  void deleteMessage(int mesid) {

        //create temp message
        Message delmsg = new Message();

        // set message id to specific that we want to delete
        delmsg.setMsgId(mesid);

      //all this is virtual to send not empty message to hibernate to remove this message
        Member m = new Member();
        m.setMemberId(1);
        delmsg.setMemberByMemberId(m);
        delmsg.setBody("mes");
        delmsg.setTitle("title");
        Member msend = new Member();
        msend.setMemberId(2);

        delmsg.setMemberBySenderId(msend);
            java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
        delmsg.setDate(sqlDate);
        MessageHome home = new MessageHome();
        // delete this message
        home.delete(delmsg);
    }

    public static Message  getMessage(int msgid)
    {
        MessageHome mshome=new MessageHome();
      Message resu=  mshome.findById(msgid);
      if(resu==null)
      {
          System.out.println(" message not Found ");
      }
      return resu;
    }
    public static Vector<Message> getMessages(int memebrid)
    {
        Vector <Message> msgVector=new Vector<Message>();
        Member dest=new Member();
        dest.setMemberId(memebrid);
        Message exmpl=new Message();

        exmpl.setMemberByMemberId(dest);
        exmpl.setMsgId(1);
        List l=new MessageHome().findByExample(exmpl);
        Iterator it=l.iterator();
        while(it.hasNext())
        {

            Message object = (Message)it.next();
            msgVector.add(object);
            System.out.println("  "+object.getTitle()+"message body is"+object.getBody()+"date of send is "+object.getDate());
        }

        return msgVector;
    }
    public static void main(String[] args) {
//        Message mm = new Message();
//        mm.setBody(" from 2 to 1 ");
//        mm.setTitle("changing  ");
//
//        Member m = new Member();
//        m.setMemberId(2);
//        mm.setMemberByMemberId(m);
//
//        Member msend = new Member();
//        msend.setMemberId(1);
//        mm.setMemberBySenderId(msend);
//
//
//        mm.setDate(new Date());
//
//        sendMessage(mm);
//  //     deleteMessage(1);
//
//
//        Message serch=getMessage(5);
//
//        System.out.println(" serch id "+serch.getBody()+""+serch.getMemberByMemberId().getMemberId());
//
       //getMessages(2);
      // getMessages(1);
    }

}

///
